import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    redirect:'/index', /*重定向*/
      children: [
        {
          path: '/index',
          component: () => import('../views/home/IndexView')
        },
        {
          path: '/detail',
          component: () => import('../views/home/DetailViewView')
        },
        {
          path: '/reg',
          component: () => import('../views/home/RegView')
        },
        {
          path: '/login',
          component: () => import('../views/home/LoginView')
        }
      ]
  },
  {
    path: '/admin',
    name: 'admin',
    redirect: '/admin/category',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AdminView.vue'),
      children:[
        {
          path:'product',
          component: () => import('../views/admin/ProductView')
        },
        {
          path:'category',
          component: () => import('../views/admin/CategoryView')
        },
        {
          path:'banner',
          component: () => import('../views/admin/BannerView')
        }
      ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
